﻿using AuroraPlatform.Tools;
using AuroraPlatform.ViewModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

namespace AuroraPlatform.View.Level5
{
    public partial class LightingView : UserControl, IPageProvider, IExportData
    {
        private LightingModel _lightingVM;
        private Prod _sourceLighting;
        private string _id;

        public LightingView()
        {
            InitializeComponent();

            FacadeBtn.Click += FacadeBtn_Click;
            GradingBtn.Click += GradingBtn_Click;
            SizeBtn.Click += SizeBtn_Click;
            LiveBtn.Click += LiveBtn_Click;
            OKBtn.Click += OKBtn_Click;
            CancelBtn.Click += CancelBtn_Click;

            for (int i = 0; i < 7; i++)
            {
                LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(120) });
            }

            for (int i = 0; i < 21; i++)
            {
                LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = new GridLength((i + 1) % 3 == 0 ? 40 : 23) });
            }

            LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });


            LightingTableFactory factory = new LightingTableFactory();
            LightingTable[] tables = new LightingTable[]
            {
                factory.CreateLighting(),
                factory.CreatePhysical(),
                factory.CreateOptics(),
                factory.CreateElectric(),
                factory.CreateAdapterLighting(),
                factory.CreateProject(),
                factory.CreateBusiness()
            };

            for (int i = 0; i < tables.Length; i++)
            {
                AddTable(tables[i], i * 3);
            }

            NaviToParam naviToParam = BusinessContext.Singleton.ParamIterator.Current;
            if (naviToParam is NaviTo5NewParam)
            {
                _lightingVM = new LightingModel();
                this.DataContext = _lightingVM;
            }
            else if (naviToParam is NaviTo5EditParam)
            {
                NaviTo5EditParam naviTo5EditParam = (NaviTo5EditParam)naviToParam;
                _id = naviTo5EditParam.ID;
            }
            else if (naviToParam is NaviTo5ViewParam)
            {
                NaviTo5ViewParam naviTo5ViewParam = (NaviTo5ViewParam)naviToParam;
                _id = naviTo5ViewParam.ID;

                foreach (ComboBox cb in _comboBoxs)
                {
                    cb.IsEnabled = false;
                }

                FacadeBtn.IsEnabled = false;
                GradingBtn.IsEnabled = false;
                SizeBtn.IsEnabled = false;
                LiveBtn.IsEnabled = false;
                OKBtn.Visibility = Visibility.Collapsed;
                CancelBtn.Visibility = Visibility.Collapsed;
            }

            if(!string.IsNullOrEmpty(_id))
                Loading();
        }

        public async void ExportToExcel()
        {
            busy.BusyContent = "正在导出数据，请稍等......";
            busy.IsBusy = true;
            WebServiceProxy proxy = new WebServiceProxy();
            string url = await proxy.SearchProdInfoToExcel(_id);
            busy.IsBusy = false;

            if (!string.IsNullOrEmpty(url))
                HtmlPage.Window.Navigate(new Uri(url));
            else
                MessageHelper.ShowError("导出数据出错。");
        }

        public async void ExportToPdf()
        {
            busy.BusyContent = "正在导出数据，请稍等......";
            busy.IsBusy = true;
            WebServiceProxy proxy = new WebServiceProxy();
            string url = await proxy.SearchProdInfoToPDF(_id);
            busy.IsBusy = false;

            if (!string.IsNullOrEmpty(url))
                HtmlPage.Window.Navigate(new Uri(url));
            else
                MessageHelper.ShowError("导出数据出错。");
        }

        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(_id))
            {
                _lightingVM = new LightingModel();
                this.DataContext = _lightingVM;
            }
            else
            {
                if (_sourceLighting != null)
                {
                    _lightingVM = ConvertForm(_sourceLighting);
                    this.DataContext = _lightingVM;

                    foreach (ComboBox cb in _comboBoxs)
                    {
                        ISourceProvider provider = cb.Tag as ISourceProvider;
                        cb.SelectedIndex = provider.GetValue(_lightingVM);
                    }
                }
            }
        }

        private async void OKBtn_Click(object sender, RoutedEventArgs e)
        {
            string error = _lightingVM.ErrorColumns;
            if (!string.IsNullOrEmpty(error))
            {
                MessageHelper.ShowMessage(string.Format("{0}输入不合法，请重新输入。", error));
                return;
            }

            if (string.IsNullOrEmpty(_id))
            {
                Prod prod = ConvertTo(_lightingVM);
                WebServiceProxy proxy = new WebServiceProxy();
                string id = await proxy.AddProd(prod.ToByteArray());
                if (!string.IsNullOrEmpty(id))
                {
                    MessageHelper.ShowMessage("添加灯具成功。");
                    _lightingVM = new LightingModel();
                    this.DataContext = _lightingVM;
                }
                else
                {
                    MessageHelper.ShowError("添加灯具失败。");
                }
            }
            else
            {
                Prod prod = ConvertTo(_lightingVM);
                WebServiceProxy proxy = new WebServiceProxy();
                bool result = await proxy.UpdateProd(prod.ToByteArray());
                if (result)
                    MessageHelper.ShowMessage("修改灯具成功。");
                else
                    MessageHelper.ShowError("修改灯具失败。");
            }
        }

        private byte[] OpenDialog()
        {
            byte[] stream = null;

            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Filter = "Image files (*.jpg, *.jpeg, *.bmp, *.png) | *.jpg; *.jpeg; *.bmp; *.png";
            bool? result = fileDialog.ShowDialog();
            if (result.HasValue && result.Value)
            {
                string ext = fileDialog.File.Name.Substring(fileDialog.File.Name.LastIndexOf('.') + 1).ToLower();
                if (ext.Equals("bmp"))
                {
                    stream = Utility.ConvertFromBMP(fileDialog.File.OpenRead());
                }
                else
                {
                    using (Stream fs = fileDialog.File.OpenRead())
                    {
                        stream = Utility.ReadFully(fs);
                    }
                }
            }
            return stream;
        }

        private void FacadeBtn_Click(object sender, RoutedEventArgs e)
        {
            byte[] bytes = OpenDialog();
            if (bytes != null && bytes.Length > 0)
                _lightingVM.UploadFacade = bytes;
        }

        private void GradingBtn_Click(object sender, RoutedEventArgs e)
        {
            byte[] bytes = OpenDialog();
            if (bytes != null && bytes.Length > 0)
                _lightingVM.UploadGrading = bytes;
        }

        private void SizeBtn_Click(object sender, RoutedEventArgs e)
        {
            byte[] bytes = OpenDialog();
            if (bytes != null && bytes.Length > 0)
                _lightingVM.UploadSize = bytes;
        }

        private void LiveBtn_Click(object sender, RoutedEventArgs e)
        {
            byte[] bytes = OpenDialog();
            if (bytes != null && bytes.Length > 0)
                _lightingVM.UploadLive = bytes;
        }

        private void AddTable(LightingTable table, int startRowIndex)
        {
            SolidColorBrush brush = new SolidColorBrush(table.Backgroud);

            Grid tableTitle = CreateTitleCell(table.Name, startRowIndex, 0);
            tableTitle.Background = brush;
            LayoutRoot.Children.Add(tableTitle);
            Grid.SetRow(tableTitle, startRowIndex);

            int startColumnIndex = 0;
            foreach (ColumnProperty column in table.Columns)
            {
                Grid columnTitle = CreateTitleCell(column.Name, startRowIndex + 1, startColumnIndex);
                columnTitle.Background = brush;
                LayoutRoot.Children.Add(columnTitle);
                Grid.SetRow(columnTitle, startRowIndex + 1);
                Grid.SetColumn(columnTitle, startColumnIndex);

                Grid bindingCell = null;
                if (column is SelectorColumn)
                {
                    bindingCell = CreateBindingSelector((SelectorColumn)column, startRowIndex + 2, startColumnIndex);
                }
                else
                {
                    bindingCell = CreateBindingCell(column.Path, startRowIndex + 2, startColumnIndex, column.Span);
                }
                bindingCell.Background = brush;
                LayoutRoot.Children.Add(bindingCell);
                Grid.SetRow(bindingCell, startRowIndex + 2);
                Grid.SetColumn(bindingCell, startColumnIndex);

                if (column.Span > 1)
                {
                    Grid.SetColumnSpan(columnTitle, column.Span);
                    Grid.SetColumnSpan(bindingCell, column.Span);
                }

                startColumnIndex++;
            }
        }

        private Grid CreateTitleCell(string text, int rowIndex, int columIndex)
        {
            Grid grid = new Grid();

            Border border = new Border();
            border.BorderBrush = new SolidColorBrush(Colors.White);

            if (rowIndex == 0)
            {
                if (columIndex > 0)
                {
                    border.BorderThickness = new Thickness(1, 0, 0, 0);
                }
                else
                {
                    border.BorderThickness = new Thickness(0);
                }
            }
            else
            {
                if (columIndex == 0)
                {
                    border.BorderThickness = new Thickness(0, 1, 0, 0);
                }
                else
                {
                    border.BorderThickness = new Thickness(1, 1, 0, 0);
                }
            }

            grid.Children.Add(border);

            TextBlock tb = new TextBlock();
            tb.Text = text;
            tb.FontSize = 13;
            tb.HorizontalAlignment = HorizontalAlignment.Center;
            tb.VerticalAlignment = VerticalAlignment.Center;

            grid.Children.Add(tb);
            return grid;
        }

        private Grid CreateBindingCell(string path, int rowIndex, int columIndex, int colSpan)
        {
            Grid grid = new Grid();
            Border border = new Border();
            border.BorderBrush = new SolidColorBrush(Colors.White);

            if (columIndex == 0)
            {
                border.BorderThickness = new Thickness(0, 1, 0, 0);
            }
            else
            {
                border.BorderThickness = new Thickness(1, 1, 0, 0);
            }

            grid.Children.Add(border);

            TextBox tb = new TextBox();
            tb.Width = 120 * colSpan;
            tb.Height = 40;
            tb.FontSize = 13;
            tb.TextAlignment = TextAlignment.Center;
            tb.TextWrapping = TextWrapping.Wrap;
            tb.Background = new SolidColorBrush(Colors.Transparent);
            tb.BorderThickness = new Thickness(0);
            tb.HorizontalAlignment = HorizontalAlignment.Center;
            tb.VerticalAlignment = VerticalAlignment.Center;
            tb.SetBinding(TextBox.TextProperty, new Binding(path) { Mode = BindingMode.TwoWay, ValidatesOnDataErrors = true });
            tb.SetBinding(TextBox.IsEnabledProperty, new Binding("IsEnabled"));

            grid.Children.Add(tb);
            return grid;
        }

        private List<ComboBox> _comboBoxs = new List<ComboBox>();

        private Grid CreateBindingSelector(SelectorColumn column, int rowIndex, int columIndex)
        {
            Grid grid = new Grid();
            Border border = new Border();
            border.BorderBrush = new SolidColorBrush(Colors.White);

            if (columIndex == 0)
            {
                border.BorderThickness = new Thickness(0, 1, 0, 0);
            }
            else
            {
                border.BorderThickness = new Thickness(1, 1, 0, 0);
            }

            grid.Children.Add(border);

            ComboBox cb = new ComboBox();
            cb.Width = 120 * column.Span;
            cb.Height = 23;
            cb.FontSize = 13;
            cb.Background = new SolidColorBrush(Colors.Transparent);
            cb.BorderThickness = new Thickness(0);
            cb.HorizontalAlignment = HorizontalAlignment.Center;
            cb.VerticalAlignment = VerticalAlignment.Top;
            cb.Tag = column.Provider;
            cb.ItemsSource = column.Provider.ItemSource;
            cb.DisplayMemberPath = "ItemName";
            cb.SelectionChanged += (sender, e) =>
            {
                ResItem resItem = cb.SelectedItem as ResItem;
                column.Provider.SetValue(_lightingVM, resItem.ItemID);
            };
            grid.Children.Add(cb);
            _comboBoxs.Add(cb);
            return grid;
        }

        private async void Loading()
        {
            WebServiceProxy proxy = new WebServiceProxy();
            _sourceLighting = await proxy.SearchProdInfo(_id);
            _lightingVM = ConvertForm(_sourceLighting);
            this.DataContext = _lightingVM;

            foreach (ComboBox cb in _comboBoxs)
            {
                ISourceProvider provider = cb.Tag as ISourceProvider;
                cb.SelectedIndex = provider.GetValue(_lightingVM);
            }
        }

        private Prod ConvertTo(LightingModel vm)
        {
            Prod.Builder builder = new Prod.Builder();
            if (!string.IsNullOrEmpty(vm.ID))
                builder.SetId(vm.ID);
            if (!string.IsNullOrEmpty(vm.ProdSeries))
                builder.SetProdSeries(vm.ProdSeries);
            builder.SetProdClass(vm.ProdClass);
            builder.SetProdPlace(vm.ProdPlace);
            if (!string.IsNullOrEmpty(vm.ProdVersion))
                builder.SetProdVersion(vm.ProdVersion);
            if (!string.IsNullOrEmpty(vm.ProdLabel))
                builder.SetProdLabel(vm.ProdLabel);

            builder.SetPhyImpact(vm.PhyImpact);
            if (!string.IsNullOrEmpty(vm.PhyWeight))
            {
                double value;
                if (double.TryParse(vm.PhyWeight, out value))
                    builder.SetPhyWeight(value);
            }

            if (!string.IsNullOrEmpty(vm.PhyColor))
                builder.SetPhyColor(vm.PhyColor);
            if (!string.IsNullOrEmpty(vm.PhySize))
                builder.SetPhySize(vm.PhySize);
            if (!string.IsNullOrEmpty(vm.PhyDefend))
                builder.SetPhyDefend(vm.PhyDefend);
            if (!string.IsNullOrEmpty(vm.PhyMaterial))
                builder.SetPhyMaterial(vm.PhyMaterial);

            if (!string.IsNullOrEmpty(vm.AdpOutput))
            {
                int value;
                if (int.TryParse(vm.AdpOutput, out value))
                    builder.SetAdpOutput(value);
            }
            builder.SetAdpClass(vm.AdpClass);
            if (!string.IsNullOrEmpty(vm.AdpCri))
            {
                int value;
                if (int.TryParse(vm.AdpCri, out value))
                    builder.SetAdpCri(value);
            }
            if (!string.IsNullOrEmpty(vm.AdpVersion))
                builder.SetAdpVersion(vm.AdpVersion);
            if (!string.IsNullOrEmpty(vm.AdpPins))
                builder.SetAdpPins(vm.AdpPins);
            if (!string.IsNullOrEmpty(vm.AdpColor))
                builder.SetAdpColor(vm.AdpColor);

            if (!string.IsNullOrEmpty(vm.ElePower))
            {
                int value;
                if (int.TryParse(vm.ElePower, out value))
                    builder.SetEleElecPower(value);
            }
            if (!string.IsNullOrEmpty(vm.EleLgtPower))
            {
                int value;
                if (int.TryParse(vm.EleLgtPower, out value))
                    builder.SetEleLgtPower(value);
            }
            if (!string.IsNullOrEmpty(vm.EleAllPower))
            {
                int value;
                if (int.TryParse(vm.EleAllPower, out value))
                    builder.SetEleAllPower(value);
            }
            builder.SetEleCtlType(vm.EleCtlType);
            builder.SetEleVoltage(vm.EleVoltage);
            if (!string.IsNullOrEmpty(vm.EleType))
                builder.SetEleType(vm.EleType);
            if (!string.IsNullOrEmpty(vm.EleShock))
                builder.SetEleShock(vm.EleShock);

            builder.SetOptExplain(vm.OptExplain);
            if (!string.IsNullOrEmpty(vm.OptEff))
            {
                double value;
                if (double.TryParse(vm.OptEff, out value))
                    builder.SetOptEff(value);
            }
            if (!string.IsNullOrEmpty(vm.OptAngle))
                builder.SetOptAngle(vm.OptAngle);

            builder.SetProjSetup(vm.ProjSetup);
            if (!string.IsNullOrEmpty(vm.ProjParts))
                builder.SetProjParts(vm.ProjParts);
            if (!string.IsNullOrEmpty(vm.ProjSize))
                builder.SetProjSize(vm.ProjSize);
            if (!string.IsNullOrEmpty(vm.ProjReport))
                builder.SetProjReport(vm.ProjReport);
            if (!string.IsNullOrEmpty(vm.ProjBaikup))
                builder.SetProjBaikup(vm.ProjBaikup);

            if (!string.IsNullOrEmpty(vm.BusIn))
            {
                double value;
                if (double.TryParse(vm.BusIn, out value))
                    builder.SetBusIn(value);
            }
            if (!string.IsNullOrEmpty(vm.BusOut))
            {
                double value;
                if (double.TryParse(vm.BusOut, out value))
                    builder.SetBusOut(value);
            }
            if (!string.IsNullOrEmpty(vm.BusMarket))
            {
                double value;
                if (double.TryParse(vm.BusMarket, out value))
                    builder.SetBusMarket(value);
            }
            if (!string.IsNullOrEmpty(vm.BusExpires))
                builder.SetBusExpires(vm.BusExpires);

            if (!string.IsNullOrEmpty(vm.PicFolder))
            {
                builder.SetPicFolder(vm.PicFolder);
                if (!string.IsNullOrEmpty(vm.PicFacade))
                    builder.SetPicFacade(vm.PicFacade.Replace(BusinessContext.Singleton.ImageUrl, ""));
                if (!string.IsNullOrEmpty(vm.PicGrading))
                    builder.SetPicGrading(vm.PicGrading.Replace(BusinessContext.Singleton.ImageUrl, ""));
                if (!string.IsNullOrEmpty(vm.PicSize))
                    builder.SetPicSize(vm.PicSize.Replace(BusinessContext.Singleton.ImageUrl, ""));
                if (!string.IsNullOrEmpty(vm.PicLive))
                    builder.SetPicLive(vm.PicLive.Replace(BusinessContext.Singleton.ImageUrl, ""));
            }

            if (vm.UploadFacade != null)
                builder.SetUploadFacade(Google.ProtocolBuffers.ByteString.CopyFrom(vm.UploadFacade));
            if (vm.UploadSize != null && vm.UploadSize.Length > 0)
                builder.SetUploadSize(Google.ProtocolBuffers.ByteString.CopyFrom(vm.UploadSize));
            if (vm.UploadGrading != null && vm.UploadGrading.Length > 0)
                builder.SetUploadGrading(Google.ProtocolBuffers.ByteString.CopyFrom(vm.UploadGrading));
            if (vm.UploadLive != null && vm.UploadLive.Length > 0)
                builder.SetUploadLive(Google.ProtocolBuffers.ByteString.CopyFrom(vm.UploadLive));
            return builder.Build();
        }

        private LightingModel ConvertForm(Prod prod)
        {
            LightingModel lm = new LightingModel();
            lm.ID = prod.Id;
            lm.ProdSeries = prod.ProdSeries;
            lm.ProdClass = prod.ProdClass;
            lm.ProdPlace = prod.ProdPlace;
            lm.ProdVersion = prod.ProdVersion;
            lm.ProdLabel = prod.ProdLabel;

            lm.PhyImpact = prod.PhyImpact;
            lm.PhyWeight = prod.PhyWeight == 0 ? string.Empty : prod.PhyWeight.ToString();
            lm.PhyColor = prod.PhyColor;
            lm.PhySize = prod.PhySize;
            lm.PhyDefend = prod.PhyDefend;
            lm.PhyMaterial = prod.PhyMaterial;

            lm.AdpOutput = prod.AdpOutput == 0 ? string.Empty : prod.AdpOutput.ToString();
            lm.AdpClass = prod.AdpClass;
            lm.AdpCri = prod.AdpCri == 0 ? string.Empty : prod.AdpCri.ToString();
            lm.AdpVersion = prod.AdpVersion;
            lm.AdpPins = prod.AdpPins;
            lm.AdpColor = prod.AdpColor;

            lm.ElePower = prod.EleElecPower == 0 ? string.Empty : prod.EleElecPower.ToString();
            lm.EleLgtPower = prod.EleLgtPower == 0 ? string.Empty : prod.EleLgtPower.ToString();
            lm.EleAllPower = prod.EleAllPower == 0 ? string.Empty : prod.EleAllPower.ToString();
            lm.EleCtlType = prod.EleCtlType;
            lm.EleVoltage = prod.EleVoltage;
            lm.EleType = prod.EleType;
            lm.EleShock = prod.EleShock;

            lm.OptExplain = prod.OptExplain;
            lm.OptEff = prod.OptEff == 0 ? string.Empty : prod.OptEff.ToString();
            lm.OptAngle = prod.OptAngle;

            lm.ProjSetup = prod.ProjSetup;
            lm.ProjParts = prod.ProjParts;
            lm.ProjSize = prod.ProjSize;
            lm.ProjReport = prod.ProjReport;
            lm.ProjBaikup = prod.ProjBaikup;

            lm.BusIn = prod.BusIn == 0 ? string.Empty : prod.BusIn.ToString();
            lm.BusOut = prod.BusOut == 0 ? string.Empty : prod.BusOut.ToString();
            lm.BusMarket = prod.BusMarket == 0 ? string.Empty : prod.BusMarket.ToString();
            lm.BusExpires = prod.BusExpires;

            if (!string.IsNullOrEmpty(prod.PicFolder))
            {
                lm.PicFolder = prod.PicFolder;

                if (!string.IsNullOrEmpty(prod.PicFacade))
                    lm.PicFacade = BusinessContext.Singleton.ImageUrl + prod.PicFacade;
                if (!string.IsNullOrEmpty(prod.PicGrading))
                    lm.PicGrading = BusinessContext.Singleton.ImageUrl + prod.PicGrading;
                if (!string.IsNullOrEmpty(prod.PicSize))
                    lm.PicSize = BusinessContext.Singleton.ImageUrl + prod.PicSize;
                if (!string.IsNullOrEmpty(prod.PicLive))
                    lm.PicLive = BusinessContext.Singleton.ImageUrl + prod.PicLive;
            }

            return lm;
        }

        public PageLevel PageLevel
        {
            get { return PageLevel.Fifth; }
        }


        public INavigate Navigation
        {
            get;
            set;
        }
    }

    public class ColumnProperty
    {
        public string Name { get; set; }
        public string Path { get; set; }

        private int _span = 1;

        public int Span
        {
            get { return _span; }
            set { _span = value; }
        }
    }

    public interface ISourceProvider
    {
        IEnumerable<ResItem> ItemSource { get; }
        void SetValue(LightingModel lm, int value);
        int GetValue(LightingModel lm);
    }

    public class SelectorColumn : ColumnProperty
    {
        public ISourceProvider Provider { get; set; }
    }

    public class LightingTable
    {
        public string Name { get; set; }
        public ColumnProperty[] Columns { get; set; }
        public Color Backgroud { get; set; }
    }

    public class LightingTableFactory
    {
        public LightingTable CreateLighting()
        {
            return new LightingTable()
            {
                Name = "产品描述",
                Columns = new ColumnProperty[]
                {
                    new ColumnProperty { Name = "产品品牌", Path = "ProdLabel" },
                    new ColumnProperty { Name = "产品系列", Path = "ProdSeries" },
                    new SelectorColumn { Name = "产品分类", Path = "ProdClass", Provider = new ProductSourceProvider() },
                    new ColumnProperty { Name = "产品型号", Path = "ProdVersion" },
                    new SelectorColumn { Name = "产    地", Path = "ProdOrgin" , Provider  = new OrginSourceProvider() },
                    new SelectorColumn { Name = "使用场所", Path = "ProdPlace", Provider = new AreaSourceProvider() },
                },
                Backgroud = Color.FromArgb(255, 242, 242, 242),
            };
        }

        public LightingTable CreatePhysical()
        {
            return new LightingTable()
            {
                Name = "物理参数",
                Columns = new ColumnProperty[]
                {
                    new ColumnProperty { Name = "材质说明", Path = "PhyMaterial" },
                    new ColumnProperty { Name = "外观颜色", Path = "PhyColor" },
                    new ColumnProperty { Name = "外形尺寸", Path = "PhySize" },
                    new ColumnProperty { Name = "防护等级", Path = "PhyDefend" },
                    new SelectorColumn { Name = "防撞击等级", Path = "PhyImpact", Provider = new ImpactSourceProvider() },
                    new ColumnProperty { Name = "产品重量", Path = "PhyWeight" },
                },
                Backgroud = Color.FromArgb(255, 217, 217, 217),
            };
        }

        public LightingTable CreateOptics()
        {
            return new LightingTable()
            {
                Name = "光学参数",
                Columns = new ColumnProperty[]
                {
                    new SelectorColumn { Name = "配光说明", Path = "OptExplain", Provider = new ExplainSourceProvider() },
                    new ColumnProperty { Name = "光束角", Path = "OptAngle" },
                    new ColumnProperty { Name = "灯具效率", Path = "OptEff" }
                },
                Backgroud = Color.FromArgb(255, 191, 191, 191)

            };
        }

        public LightingTable CreateElectric()
        {
            return new LightingTable()
            {
                Name = "电气参数",
                Columns = new ColumnProperty[]
                {
                    new ColumnProperty { Name = "防触电等级", Path = "EleShock" },
                    new SelectorColumn { Name = "工作电压", Path = "EleVoltage", Provider = new VoltageSourceProvider() },
                    new ColumnProperty { Name = "电器类型", Path = "EleType"},
                    new ColumnProperty { Name = "电器功耗", Path = "ElePower" },
                    new ColumnProperty { Name = "光源功率", Path = "EleLgtPower" },
                    new ColumnProperty { Name = "整灯功耗", Path = "EleAllPower" },
                    new SelectorColumn { Name = "控制方式", Path = "EleCtlType", Provider = new ControlTypeSourceProvider() }
                },
                Backgroud = Color.FromArgb(255, 166, 166, 166)
            };
        }

        public LightingTable CreateAdapterLighting()
        {
            return new LightingTable()
            {
                Name = "适配光源",
                Columns = new ColumnProperty[]
                {
                    new SelectorColumn { Name = "光源种类", Path = "AdpClass", Provider = new AdapterClassSourceProvider() },
                    new ColumnProperty { Name = "光源型号", Path = "AdpVersion" },
                    new ColumnProperty { Name = "色温或颜色", Path = "AdpColor" },
                    new ColumnProperty { Name = "显色性", Path = "AdpCri" },
                    new ColumnProperty { Name = "光输出", Path = "AdpOutput" },
                    new ColumnProperty { Name = "插脚形式", Path = "AdpPins" }
                },
                Backgroud = Color.FromArgb(255, 128, 128, 128)
            };
        }

        public LightingTable CreateProject()
        {
            return new LightingTable()
            {
                Name = "工程参数",
                Columns = new ColumnProperty[]
                {
                    new SelectorColumn { Name = "安装方式", Path = "ProjSetup", Provider = new SetupSourceProvider() },
                    new ColumnProperty { Name = "安装尺寸", Path = "ProjSize" },
                    new ColumnProperty { Name = "认证及检测报告", Path = "ProjReport" },
                    new ColumnProperty { Name = "备    注", Path = "ProjBaikup" },
                    new ColumnProperty { Name = "可选配件", Path = "ProjParts", Span = 3 }
                },
                Backgroud = Color.FromArgb(255, 109, 109, 109)

            };
        }

        public LightingTable CreateBusiness()
        {
            return new LightingTable()
            {
                Name = "商务参数",
                Columns = new ColumnProperty[]
                {
                    new ColumnProperty { Name = "参考进价", Path = "BusIn" },
                    new ColumnProperty { Name = "市场参考价", Path = "BusMarket" },
                    new ColumnProperty { Name = "参考售价", Path = "BusOut" },
                    new ColumnProperty { Name = "参考货期", Path = "BusExpires" }
                },
                Backgroud = Color.FromArgb(255, 89, 89, 89)
            };
        }
    }
}
